package com.hailiang.controller;

import com.hailiang.dom.UnameQuery;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/loginservlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String pword = req.getParameter("password");

        UnameQuery unameQuery = new UnameQuery();
        try {
            //查询账号是否存在
            boolean b = unameQuery.queryName(username);
            if(b){
             //根据账号查询密码
                String s = unameQuery.queryPwordFromUname(username);
                if(pword.equals(s)){
                    //登录成功
                    resp.sendRedirect("index03.html");
                }
            }


        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
